<?php

class Admin_TourController extends Zend_Controller_Action
{

    protected $_em;
    protected $_repo;
    
    public function init()
    {
        $this->_helper->layout()->menu=array("tour","Tour");
        
        $this->_em = Zend_Registry::get('doctrine');
        $this->_flash = $this->_helper->getHelper('FlashMessenger');
    }

	/************** TOURS *************/
	public function tourAction(){
	    $this->view->manager = 'MANAGEMENT TOUR LIST';
	    $id = $this->_getParam('id', 0);
	    $this->_repo = $this->_em->getRepository('Entities\HaeTour');
	    if ( $id != 0 )
	    {
	    	$this->_repo->deleteById($id);
	    }
	    $this->view->object = $this->_repo->findAll();
	}
	public function detailtourAction(){
	    $id = $this->_getParam('id', 0);
	    
	    $form = new Admin_Form_Tour();
// 	    $formPromotion = new Admin_Form_Promotion();
	    $this->view->form = $form;
	     
	    if($id == 0 )
	    {
	    	$this->view->manager = 'ADD NEW TOUR';
	    	if($this->getRequest()->isPost())
	    	{
	    		$this->_saveCareer($this->getRequest()->getPost());
	    		$this->_helper->flashMessenger('Add successfully');
	    	}
	    }
	    else
	    {
	    	$this->_repo = $this->_em->getRepository('Entities\HaeTour');
	    	$data = $this->_repo->findOneById($id);
	    	$this->_repo = $this->_em->getRepository('Entities\HaeSeo');
	    	$dataSeo = $this->_repo->findOneById($data->getseoId());
	    	
 	    	$data->setInclusions(explode('_',$data->getInclusions()));
 	    	$data->setExclusions(explode('_',$data->getExclusions()));
 	    	$data->setCancellation(explode('_',$data->getCancellation()));
 	    	$data->setTheme(explode('_',$data->getTheme()));
 	    	
 	    	
	    	$this->view->manager = 'EDITOR  TOUR :'.$data->getTitleEn();
	    	$form->populate($data->toArray());
	    	$form->populate($dataSeo->toArray());
	    	if($this->getRequest()->isPost())
	    	{
	    		$this->_helper->flashMessenger('Edit successfully');
	    	}
	    }
	}
	
	
}